package com.ruoyi.common.core.utils.exptimpt;

import com.ruoyi.common.core.domain.BaseExcel;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 基础校验类 - 责任链
 */
@Slf4j
public abstract class ExImportHandlerChain {


    private ExImportHandlerChain next;

    /**
     * 构建校验对象链
     */
    public static ExImportHandlerChain link(ExImportHandlerChain first, ExImportHandlerChain... chains) {
        ExImportHandlerChain head = first;
        for (ExImportHandlerChain chain : chains) {
            head.next = chain;
            head = chain;
        }
        return first;
    }

    /**
     * 处理
     */
    public abstract <T extends BaseExcel> boolean handle(List<T> dataList, AbstractExImportStrategy<T> importStrategy);

    /**
     * 处理下一个
     */
    protected <T extends BaseExcel> boolean handleNext(List<T> dataList, AbstractExImportStrategy<T> importStrategy) {
        if (next == null) {
            return true;
        }
        return next.handle(dataList, importStrategy);
    }

}